<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>卡片冻结</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all"/>
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all"/>
    <link rel="stylesheet" th:href="@{/layui_ext/dtree/dtree.css}" media="all"/>
    <link rel="stylesheet" th:href="@{/layui_ext/dtree/font/dtreefont.css}" media="all"/>
</head>
<body class="childrenBody">
<!-- 查询条件开始 -->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 5px;">
    <legend>查询条件</legend>
</fieldset>
<blockquote class="layui-elem-quote">
    <form action="" method="post" id="searchFrm" lay-filter="searchFrm" class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">信用卡号</label>
                <div class="layui-input-inline">
                    <input type="text" name="cardnum" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-block" style="float: left;margin-left: 0px">
                    <button type="button" class="layui-btn" lay-submit="" lay-filter="doSearch"><span
                            class="layui-icon layui-icon-search"></span>查询
                    </button>
                </div>
            </div>
        </div>
    </form>
</blockquote>
<!-- 查询条件结束-->


<!-- 数据表格开始 -->
<div>
    <table class="layui-hide" id="adminTable" lay-filter="adminTable"></table>
    <script type="text/html" id="orderNum">
        {{d.LAY_TABLE_INDEX+1}}
    </script>
    <div id="adminRowBar" style="display: none;">
        <button type="button" shiro:hasPermission="account:freeze" lay-event="update" class="layui-btn layui-btn-sm">冻结</button>
        <button type="button" shiro:hasPermission="account:select" lay-event="resetPassword" class="layui-btn layui-btn-sm"></span>查看详情</button>
        <button type="button" shiro:hasPermission="account:unfreeze" lay-event="lock" class="layui-btn layui-btn-sm layui-btn-danger">取消冻结</button>
    </div>
</div>

<!-- 数据表格结束 -->

<!-- 添加和修改的弹出层开始 -->
<div style="display: none;padding: 5px" id="addOrUpdateDiv">
    <form action="" method="post" style="padding: 10px;" class="layui-form layui-form-pane" id="dataFrm" lay-filter="dataFrm">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" readonly name="username" id="username" lay-verify="required" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">卡号</label>
            <div class="layui-input-block">
                <input type="text" readonly name="cardnum" id="cardnum" lay-verify="required" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">证件号</label>
            <div class="layui-input-block">
                <input type="text" readonly name="identityId" id="identityId" lay-verify="required" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <input type="text" readonly name="phonenum" id="phonenum" lay-verify="required" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="text" readonly name="status" id="status" lay-verify="required" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center;">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="doSubmit">
                    <span class="layui-icon layui-icon-add-1"></span>冻结
                </button>
                <button type="button" class="layui-btn" lay-submit="" lay-filter="doSubmit2">
                    <span class="layui-icon layui-icon-add-1"></span>取消冻结
                </button>
            </div>
        </div>
    </form>
</div>
<!-- 添加和修改的弹出层结束 -->

<script type="text/javascript" th:src="@{/layui/layui.js}"></script>
<script type="text/javascript">
    var tableIns;
    layui.extend({
        dtree: '/layui_ext/dtree/dtree'   // {/}的意思即代表采用自有路径，即不跟随 base 路径
    }).use(['jquery', 'form', 'table', 'layer', 'dtree'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var table = layui.table;
        var layer = layui.layer;
        var dtree = layui.dtree;
        //加载 数据
        tableIns = table.render({
            elem: '#adminTable'
            , url: '/credit/tofreeze'
            , toolbar: '#adminToolBar' //开启头部工具栏，并为其绑定左侧模板
            , title: '用户数据表'
            , height: 'full-250'
            , page: true
            , cols: [
                [
                    {field: 'orderNum', title: '排序码', align: 'center',templet:'#orderNum'}
                    , {field: 'userName', title: '用户名', align: 'center'}
                    ,{field: 'certificate_num', title: '身份证号', align: 'center'}
                    , {field: 'cardnum', title: '卡号', align: 'center'}
                    , {field: 'phonenumber', title: '联系电话', align: 'center'}
                    , {field: 'status', title: '状态', align: 'center'}
                    , {fixed: 'right', title: '操作', toolbar: '#adminRowBar', align: 'center', width: '400'}
                ]
            ]
            , done: function (res, curr, count) { //处理删除某一页最后一条数据的BUG
                if (res.data.length == 0 && curr != 1) {
                    tableIns.reload({
                        page: {
                            curr: (curr - 1)
                        }
                    });
                }
            }
        });

        //模糊查询
        form.on("submit(doSearch)", function (data) {
            tableIns.reload({
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });

        //监听工具条的事件
        table.on("toolbar(adminTable)", function (obj) {
            switch (obj.event) {
                case 'add':
                    openAddLayer();
                    break;
            };
        });

        //监听行工具条的事件
        table.on("tool(adminTable)", function (obj) {
            var data = obj.data; //获得当前行数据
            switch (obj.event) {
                case 'update':
                    openUpdateUserLayer(data);
                    break;
                case 'resetPassword':
                    resetPwd(data);
                    break;
                case 'lock':
                    distributeRole(data);
                    break;
            };
        });

        var mainIndex;
        var url;

        //打开添加的弹出层
        function resetPwd(data) {
            mainIndex = layer.open({
                type: 1,
                content: $("#addOrUpdateDiv"),
                area: ['800px', '500px'],
                title: '添加用户',
                success: function () {
                    $("#xuhao").val(data.orderNum);
                    $("#username").val(data.userName);
                    $("#identityId").val(data.certificate_num);
                    $("#cardnum").val(data.cardnum);
                    $("#phonenum").val(data.phonenumber);
                    $("#status").val(data.status);
                }
            });
        }

        //冻结
        function openUpdateUserLayer(data) {
            $.post("/credit/upstatus",
                "cardnum="+data.cardnum+"&type="+5,
                function (data) {
                    layer.msg(data.data);
                    tableIns.reload();
                }),"json"
        }

        //取消冻结
        function distributeRole(data) {
            $.post("/credit/upstatus",
                "cardnum="+data.cardnum+"&type="+1,
                function (data) {
                    layer.msg(data.data);
                    tableIns.reload();
                }),"json"
        }


        form.on("submit(doSubmit)", function (obj) {
            $.post("/credit/upstatus",
                "cardnum="+$("#cardnum").val()+"&type="+5,
                function (data) {
                    layer.msg(data.data);
                    layer.close(mainIndex);
                    tableIns.reload();
                },"json");
            return false;
        });

        form.on("submit(doSubmit2)", function (obj) {
            $.post("/credit/upstatus",
                "cardnum="+$("#cardnum").val()+"&type="+1,
                function (data) {
                    layer.msg(data.data);
                    layer.close(mainIndex);
                    tableIns.reload();
                },"json");
            return false;
        });
    });
</script>

</body>
</html>